package invite

import (
	"context"
	"fmt"
	"gitee.com/enjoy_5/sigin-rpc/internal/sever"
	pb "gitee.com/enjoy_5/sigin-rpc/proto/invite"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

type ServerInvite struct {
	pb.UnimplementedInviterServer
}

func (s *ServerInvite) InviteCreate(ctx context.Context, in *pb.InviteCreateRequest) (*pb.InviteCreateResponse, error) {
	_, err := sever.CreateInvite(in)
	fmt.Println(err)
	if err != nil {
		return nil, status.Errorf(codes.Unimplemented, "method InviteCreate not implemented 已经邀请过该好友")

	}
	return &pb.InviteCreateResponse{}, nil
}

func (s *ServerInvite) GetInvite(ctx context.Context, in *pb.GetInviteRequest) (*pb.GetInviteResponse, error) {
	stu, err := sever.GetInvite(in)
	if err != nil {
		return nil, status.Errorf(codes.Internal, "internal error: %s", err)
	}
	var invite []*pb.Info
	for _, v := range stu {
		invite = append(invite, &pb.Info{InviterId: v.InviterId, InviteeId: v.InviteeId})
	}
	return &pb.GetInviteResponse{
		Info: invite,
	}, nil
}
